<?php

/*
 *公共数据部分
 * Desc  准备弃用
 */
namespace app\comm\controller;
use think\Controller;
use think\Db;
use app\comm\controller\BaseController;
use app\comm\service\UserService;
class WebLogController extends BaseController {

	/**
	 * 必须是登录的用户才能进入此控制器
	 */
	protected $map=[];
	public $userinfo;
	public function __construct(){
		parent::__construct();

		if(method_exists($this, '__autoload_weixin')){
			$this->__autoload_weixin();
		}	
		if(!session('_user_uid_')){
			if (request()->isAjax()){
				echo json_encode(['status'=>9,'还没登录']);die;
			}
			$this->redirect('outlo/index');
		}
		//用户信息，包含用户的logo，头像
		$userinfo = new UserService();
		$uid      = session('_user_uid_')['uid'];
		$useri    = $userinfo->getUserInfoByCash($uid);	
		$this ->userinfo = $useri;
		if(empty($this ->userinfo['nickname'])){
			if (request()->isAjax()){
				echo json(['status'=>8,'还没信息不完整']);die;
			}
			$this->redirect('outlo/saveuserinfo');
		}
		if(method_exists($this, '__constr_metho')){
			$this->__constr_metho();
		}
		if(method_exists($this, '__autoload_web')){
			$this->__autoload_web();
		}
		if(method_exists($this, '__autoindex')){
			$this->__autoindex();
		}
		
		$this ->levepoint($this ->userinfo);
	}

	public function  __autoload_web(){

	}
	
	

	/**
	 * 等级积分计算 构造函数中计算
	 */
	protected function levepoint($user){
		$levelid = "";
		$levelsn = "";
		$list = Db::table("ys_sys_level")->order("score desc")->select();
		foreach ($list as $key => $value) {
             if($user["level_point"] > $value["score"]){
             	$levelid = $value["id"];
             	$levelsn = $value["title"];
             	break;
             }
		}
		$da=["level_id"=>$levelid,"level_sn"=>$levelsn];
		if($levelid==$user["level_id"])return;
		$list = Db::table("ys_user")->where("uid",$user["uid"])->update($da);
		
	}
}

